package com.thread.other;

import java.util.concurrent.TimeUnit;

public class InnerClassRunnable1 {

	private int countDown = 5;
	private Inner inner;

	// 使用内部类
	private class Inner implements Runnable {
		Thread t;

		Inner(String name) {
			t = new Thread(this, name);
			t.start();
		}

		public void run() {
			while (true) {
				System.out.print(this + ",");
				if (--countDown == 0) {
					return;
				}
				try {
					TimeUnit.MILLISECONDS.sleep(10);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}

		public String toString() {
			return t.getName() + ": " + countDown;
		}
	}

	public static void main(String[] args) {
		InnerClassRunnable1 in = new InnerClassRunnable1();
		in.inner = in.new Inner("InnerClassRunnable1");
	}

}
